<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件化学习</title>
</head>
<body>
<div id="app1">
    <h1>全局组件</h1>
    <counter></counter><br/><br/>
    <counter1></counter1><br/><br/>
    <counter2></counter2><br/><br/>
</div>
<div id="app2">
    <h1>局部组件</h1>
    <counter></counter><br/><br/>
    <counter1></counter1><br/><br/>
    <counter2></counter2><br/><br/>
</div>
<div id="app3">
    <h1>全局组件</h1>
    <counter></counter><br/><br/>
    <counter1></counter1><br/><br/>
    <counter2></counter2><br/><br/>
</div>
<script src="vue.js"></script>
<script>
    Vue.component("counter", {
        template: `<button v-on:click="click">点击次数 = {{count}} [全局组件]</button>`,
        data() {
            return {count: 0};
        },
        methods: {
            click() {
                this.count++;
            }
        }
    })
    const Component = {
        template: `<button v-on:click="click">点击次数 = {{count}} [局部组件]</button>`,
        data() {
            return {count: 0};
        },
        methods: {
            click() {
                this.count++;
            }
        }
    }
    new Vue({
        el: "#app1"
    })
    new Vue({
        el: "#app2",
        components: {
            'counter1': Component
        }
    })
    new Vue({
        el: "#app3",
        components: {
            counter2: Component
        }
    })
</script>
</body>
</html>